/*
 * test_List.c
 *
 *  Created on: 2011-9-18
 *      Author: Jesse Meng [pingf0@gmail.com]
 */

#include "IntList.h"

int each_print(IntListNode *s,void *p){
	printf("-----%d\n",s->value);
	return 0;
}

typedef struct {
	int v;
}VV;

int each_find(IntListNode *s,VV *p){
	static int i=0;
	int v=(p->v);
	if(s->value==v){
		printf(">>%d %d",v,i);
		i=0;
		return 1;
	}
	printf("++%d",i);
	++i;
	return 0;
}
int main(){
	//测试构建
	int a[]={1,2,3,4,5};
	IntList *l=NEW(IntList,PP(AP,.len=5,.data=a));
	STT(l,IntList)->view(l);
	int i=0;
	printf("\n%d\n",l->len);
	while(i<l->len){
		printf("%d ",STT(l,IntList)->at(l,i));
		++i;
	}
	printf("\n*\n");
	//
	IntList *l2=NEW(IntList,PP(AP,.len=5,.data=a));
	STT(l,IntList)->view(l2);
	STT(l,IntList)->insert1(l2,l2->len,7);
	STT(l,IntList)->view(l2);
	STT(l,IntList)->insert1(l2,0,0);
	STT(l,IntList)->view(l2);
	STT(l,IntList)->insert1(l2,-1,6);
	STT(l,IntList)->view(l2);

	DELETE0(l);
	DELETE0(l2);

	printf("\n**\n");
	IntList *l3=NEW(IntList,PP(AP,.len=5,.data=a));
	STT(l3,IntList)->view(l3);
	int b[]={6,7};
	int c[]={-2,-1,0};
	int d[]={0,0,0};
	STT(l3,IntList)->insert(l3,l3->len,b,2);
	STT(l3,IntList)->view(l3);
	STT(l3,IntList)->insert(l3,0,c,3);
	STT(l3,IntList)->view(l3);

	STT(l3,IntList)->insert(l3,6,d,3);
	STT(l3,IntList)->view(l3);
	printf("\n\n");
	STT(l3,IntList)->remove(l3,-3,2);
	STT(l3,IntList)->view(l3);
	//STT(l3,IntList)->remove(l3,0,l3->len-1);
	STT(l3,IntList)->eachSel(1);
	STT(l3,IntList)->eachDo(l3,each_print,1,NULL);
	STT(l3,IntList)->eachDo(l3,each_find,PP(VV,.v=4));


	printf("\n");
	STT(l3,IntList)->view(l3);

	printf("\n");
	STT(l3,IntList)->shiftL(l3);
	STT(l3,IntList)->view(l3);

	printf("\n");
	STT(l3,IntList)->shiftR(l3);
	STT(l3,IntList)->view(l3);
	printf("\n");
	STT(l3,IntList)->shiftR(l3);
	STT(l3,IntList)->view(l3);
	printf("\n");
	STT(l3,IntList)->shiftR(l3);
	STT(l3,IntList)->view(l3);
	printf("\n");
	STT(l3,IntList)->shiftR(l3);
	STT(l3,IntList)->view(l3);
	printf("\n");
	STT(l3,IntList)->shiftR(l3);
	STT(l3,IntList)->view(l3);
	printf("\n");
	STT(l3,IntList)->shiftR(l3);
	STT(l3,IntList)->view(l3);
	printf("\n");
	STT(l3,IntList)->shiftR(l3);
	STT(l3,IntList)->view(l3);
	printf("\n");
	STT(l3,IntList)->shiftR(l3);
	STT(l3,IntList)->view(l3);
	printf("\n");
	STT(l3,IntList)->shiftR(l3);
	STT(l3,IntList)->view(l3);
	printf("\n");
	STT(l3,IntList)->shiftR(l3);
	STT(l3,IntList)->view(l3);
	printf("\n");
	STT(l3,IntList)->shiftR(l3);
	STT(l3,IntList)->view(l3);

	printf("\n");
	STT(l3,IntList)->shiftR(l3);
	STT(l3,IntList)->view(l3);
	DELETE0(l3);
	return 0;
}
